package com.datoucai.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/cookie")
public class CookieController {

    @GetMapping("/setCookie")
    public String setCookie(HttpServletRequest request,HttpServletResponse response) {
        // 创建一个Cookie
        Cookie cookie = new Cookie("myCookieName", "myCookieValue");
        // 设置cookie的属性（可选）
        cookie.setMaxAge(100);
        cookie.setPath("/");
        // 将cookie添加到响应中
        response.addCookie(cookie);


        Cookie cookie1 = new Cookie("userId", "123456");
        // 设置cookie的属性（可选）
        cookie1.setMaxAge(100);
        cookie1.setPath("/");
        // 将cookie添加到响应中
        response.addCookie(cookie1);
        
        return "Cookie has been set!";
    }
}